package com.sky.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
//import com.just.agentweb.AgentWeb;
//import com.just.agentweb.DefaultWebClient;
import androidx.appcompat.app.AppCompatActivity;

/**
 * Created by Min
 * Date 2022/4/13  16:56
 */
public class WebViewActivity extends AppCompatActivity  {
    private WebView webView;
    private RelativeLayout rl_body;
//    protected AgentWeb mAgentWeb;



//    @Override
//    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_web_view);
//
//        rl_body = findViewById(R.id.rl_body);
////        webView = findViewById(R.id.web_view);
//
////        AgentWeb.with(this)
////                .setAgentWebParent(rl_body, new LinearLayout.LayoutParams(-1, -1))
////                .useDefaultIndicator()
//////                .setWebViewClient(getWebViewClient())
//////                .setWebChromeClient(new BaseWebChromeClient(mTitleTextView))
////                .setMainFrameErrorView(R.layout.agentweb_error_page, -1)
////                .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
////                .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)//打开其他应用时，弹窗咨询用户是否前往其他应用
////                .interceptUnkownUrl() //拦截找不到相关页面的Scheme
////                .createAgentWeb()
////                .ready()
////                .go("https://sharetest.zhixiangchengshi.com/zxcs-view/#/pages/food/manager/qacManage/qacManage?backUserId=12857&merchantId=82784&shopId=1169&type=1");
//
////        webView = agentWeb.getWebCreator().getWebView();
//
////        agentWeb.getJsAccessEntrace().quickCallJs();
//
////        AgentWeb mAgentWeb = AgentWeb.with(this)
////                .setAgentWebParent(rl_body, new LinearLayout.LayoutParams(-1, -1))
////                .useDefaultIndicator()
////                .setMainFrameErrorView(R.layout.agentweb_error_page, -1)
////                .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
////                .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)//打开其他应用时，弹窗咨询用户是否前往其他应用
////                .interceptUnkownUrl() //拦截找不到相关页面的Scheme
////                .createAgentWeb()
////                .ready()
////                .go("");
//
////        WebSettings webSettings = webView.getSettings();
////        webSettings.setDisplayZoomControls(false);
////        webSettings.setJavaScriptEnabled(true); // 设置支持javascript脚本
////        webSettings.setAllowFileAccess(true); // 允许访问文件
////        webSettings.setBuiltInZoomControls(true); // 设置显示缩放按钮
////        webSettings.setSupportZoom(true); // 支持缩放
////        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
////        webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
////        webSettings.setUseWideViewPort(true); // 自适应屏幕
////        webSettings.setLoadWithOverviewMode(true);
////        //开启DomStorage缓存
////        webSettings.setDomStorageEnabled(true);
////
////
////        webView.setWebViewClient(new WebViewClient() {
////            @Override
////            public boolean shouldOverrideUrlLoading(WebView view, String url) {
////                //在当前Activity打开
////                view.loadUrl(url);
////                return true;
////            }
////
////            @Override
////            public void onPageFinished(WebView webView, String s) {
////                super.onPageFinished(webView, s);
////            }
////
////            @Override
////            public void onReceivedError(WebView webView, int i, String s, String s1) {
////                super.onReceivedError(webView, i, s, s1);
////            }
////        });
////
//////        webView.loadUrl("https://sharetest.zhixiangchengshi.com/zxcs-view/#/pages/food/manager/qacManage/qacManage?backUserId=12857&merchantId=82784&shopId=1169&type=1");
////        webView.addJavascriptInterface(new WebAndroid(), "android");
//    }
//
//    private class WebAndroid {
//        private Handler mHandler = new Handler(Looper.getMainLooper());
//
//        /**
//         * 选择图片
//         */
//        @JavascriptInterface
//        public void chooseFile() {
//            mHandler.post(() -> {
//                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
//                intent.addCategory(Intent.CATEGORY_OPENABLE);
//                intent.setType("application/msword");
//                intent.setType("application/pdf");
//                intent.setType("image/jpeg");
//                intent.setType("image/png");
//
//                startActivityForResult(intent, 1);
//            });
//        }
//
//        /**
//         * 关闭页面
//         */
//        @JavascriptInterface
//        public void back() {
//            finish();
//        }
//
//        /**
//         * 下载文件
//         */
//        @JavascriptInterface
//        public void downFile(String path) {
//            finish();
//        }
//
//        /**
//         * 分享文件
//         */
//        @JavascriptInterface
//        public void shareFile(String path) {
//            finish();
//        }
//    }
//
//    @Override
//    public void onBackPressed() {
//        if (webView.canGoBack()){
//            webView.goBack();
//        } else {
//            finish();
//        }
//    }
//
//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if (requestCode == 1) {
//            webView.loadUrl("javascript:setImgUrl('baidu.jpg','http://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1-66368c33f8.png')");
//        }
//    }
}
